home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / c / win_clp.com / TWINCLIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-23  |  2.6 KB  |  91 lines

  1. /*
  2. TWINCLIP.C
  3. Test WinClip -- non-Windows program reads Windows clipboard
  4.  
  5. NOTE: I originally wrote this as a sample program for
  6. 286|DOS-Extender, a new product from Phar Lap Software.
  7. 286|DOS-Extender runs protected-mode programs, produced with the
  8. Microsoft C -Lp switch, under MS-DOS. However, if you compile
  9. for real mode, this also stands as an example of using the
  10. Windows Clipboard services (INT 2Fh AH=17h). Call me if you
  11. have any questions:
  12.     Andrew Schulman
  13.     Phar Lap Software
  14.     (617) 661-1510 x238
  15.     andrew@pharlap.com
  16.     CIS 76320,302
  17.         
  18. Documentastion for these services is available in INTRLIST, a
  19. hypertext database of interrupts and functions that accompanies the
  20. book _Undocumented DOS: A Programmer's Guide to Reserved MS-DOS
  21. Functions and Data Structures_, edited by Andrew Schulman (Reading
  22. MA: Addison-Wesley, 1990, 694 pages, ISBN 0-201-57064-5, $39.95). If
  23. you can't find the book in your local bookstore, call Addison-Wesley
  24. at 617-944-3700, and order it from them.
  25.  
  26. SEE ALSO WINCLIP.C, PWINCLIP.C, WINCLIP.H
  27.  
  28. TWINCLIP.C -- test file; no change needed for 286|DOS-Extender
  29. WINCLIP.H -- header file for Windows API for DOS apps
  30. WINCLIP.C -- real mode implementation of API
  31. PWINCLIP.C -- protected mode implementation of API
  32.  
  33. real mode:
  34.     C:\>cl twinclip.c winclip.c
  35.     C:\>\win30\win /e
  36. within Windows DOS box:     
  37.     C:\>twinclip
  38.         
  39. protected mode:
  40.     C:\>cl -Lp twinclip.c pwinclip.c
  41.     C:\>\win30\win /e
  42. with Windows DOS box:
  43.     C:\>run286 twinclip
  44.         
  45. sample output:      
  46. WINOLDAP v. 2.0
  47. Resolution: 640 x 480 (16 colors)
  48. Clipboard data: 1248 bytes
  49. Clipboard contents:
  50.     ... [contents of clipboard]
  51. */
  52.  
  53. #include <stdlib.h>
  54. #include <stdio.h>
  55.  
  56. #include "winclip.h"
  57.  
  58. void fail(char *s) { puts(s); exit(1); }
  59.  
  60. int main(int argc, char *argv[])
  61. {
  62.     unsigned long size;
  63.     char far *buf;
  64.     int maj, min;
  65.     
  66.     if (WinOldApVersion(&maj, &min))
  67.         printf("WINOLDAP v. %d.%d\n", maj, min);
  68.     else
  69.         fail("This program requires WINOLDAP");
  70.  
  71.     printf("Resolution: %u x %u (%u colors)\n",
  72.         GetDeviceCaps(HORZRES), GetDeviceCaps(VERTRES),
  73.         GetDeviceCaps(NUMCOLORS));
  74.     
  75.     OpenClipboard();
  76.     
  77.     if (! (size = GetClipboardSize(CF_TEXT)))
  78.         puts("No text in clipboard");
  79.     else if (buf = GetClipboardData(CF_TEXT))
  80.     {
  81.         printf("Clipboard data: %lu bytes\n", size);
  82.         printf("Clipboard contents:\n%Fs\n", buf);  /* Far string */
  83.         FreeClipboardData(buf);
  84.     }
  85.  
  86.     CloseClipboard();
  87.  
  88.     return 0;
  89. }
  90.  
  91.